package common

import (
	"gitee.com/dingyangzhuang/dingutils/dlog"
	"log/slog"
	"time"
)

// 命令执行超时时间
var TIMEOUT time.Duration = 35 * time.Second
var ADMIN_USER string
var log *slog.Logger
var EncryptionKey string
var NACOSCONFIGS NacosConfig

func InitLog() {
	//在日志初始化后再去获取日志
	log = dlog.GetLogger()
}
func InitConstat(config NacosConfig) {

	ADMIN_USER = config.AdminUser
	TIMEOUT = time.Duration(config.SshTimeout) * time.Second
	EncryptionKey = config.EncryptionKey
	NACOSCONFIGS = config
}

// 解析nacos_test.yml配置文件 和上边的字段保持一致
type NacosConfig struct {
	NacosServer   NacosServerConfig `json:"nacosServer" yaml:"nacosServer" mapstructure:"nacosServer"`
	EncryptionKey string            `json:"encryptionKey" yaml:"encryptionKey" mapstructure:"encryptionKey"` //密码加密key
	AdminUser     string            `json:"adminUser" yaml:"adminUser"`
	SshTimeout    int               `json:"sshTimeout" yaml:"sshTimeout"`
	Wechat        WechatConfig      `json:"wechat" yaml:"wechat" mapstructure:"wechat"`
}
type WechatConfig struct {
	Users      string `json:"users" yaml:"users" mapstructure:"users"`
	Agentid    int    `json:"agentid" yaml:"agentid" mapstructure:"agentid"`
	Corpid     string `json:"corpid" yaml:"corpid" mapstructure:"corpid"`
	Corpsecret string `json:"corpsecret" yaml:"corpsecret" mapstructure:"corpsecret"`
}
type NacosServerConfig struct {
	ServerName  string `json:"serverName" yaml:"serverName" mapstructure:"serverName"`
	ServerPort  string `json:"serverPort" yaml:"serverPort" mapstructure:"serverPort"`
	Weight      string `json:"weight" yaml:"weight" mapstructure:"weight"`
	ClusterName string `json:"clusterName" yaml:"clusterName" mapstructure:"clusterName"`
	Group       string `json:"group" yaml:"group" mapstructure:"group"`
}
